import { commonVisit } from './share';

export function bridgeConnect(act) {
    if (!WPT.$curPage) {
        return;
    }
    const curReact = WPT[`Page-${WPT.$curPage.data('page')}`];
    const { showHideList = [] } = WPT.$curPage[0];

    // notice 2.0.0版本及其之前版本 在调用App的图片/视频上传方法的时候，此方法也会被触发
    if (curReact && act == 'show') {
        curReact.show && curReact.show('fromApp');
        showHideList.length != 0 &&
            showHideList.forEach((instance) => {
                $.isFunction(instance.onPageShow) && instance.onPageShow('fromApp');
            });
        commonVisit(true);
    }

    if (curReact && act == 'hide') {
        curReact.hide && curReact.hide();
        showHideList.length != 0 &&
            showHideList.forEach((instance) => {
                $.isFunction(instance.onPageHide) && instance.onPageHide();
            });
    }
}
